<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/include/include.jsp"%>
<script type="text/javascript">
<!--
	setTimeout('ajaxConsole(true)',$(':hidden[name=logAutoRefreshTime]').val());

	function ajaxConsole(autoReflesh){
		var logFileLengthField = $(':hidden[name=logFileLength]');
		var logFileContentField = $('textarea[name=logFileContent]');
		var logPauseAction = $(':hidden[name=logPauseAction]').val();
		if(!logFileContentField.get(0))return;
		$.ajax({
			type:'GET',
			url:'<c:url value="/system/log/ajaxConsole"/>',
			data:{start:logFileLengthField.val()},
			cache:false,
			success:function(data){
				
				logFileLengthField.val(data.substring(0,data.indexOf('-')));
				
				logFileContentField.append(data.substring(data.indexOf('-')+1,data.length-1));
				
				if(logFileContentField.is(':visible'))
					moveCursorToEnd(logFileContentField.get(0));
				if(logPauseAction=='0' && autoReflesh)
					setTimeout('ajaxConsole(true)',$(':hidden[name=logAutoRefreshTime]').val());
			}
		});
	}	
	
	
	function moveCursorToEnd(el) {
	    if (typeof el.selectionStart == "number") {
	        el.selectionStart = el.selectionEnd = el.value.length;
	    } else if (typeof el.createTextRange != "undefined") {
	        el.focus();
	        var range = el.createTextRange();
	        range.collapse(false);
	        range.select();
	    }
	}
	function pauseLog(link){
		var logPauseActionField = $(':hidden[name=logPauseAction]');
		if(logPauseActionField.val()=='0'){
			logPauseActionField.val('1');
			$(link).text('<fmt:message key="page.system.log.recover"/>');
			$('#handRefreshFileLogLi').show();
			$('#autoRefreshFileLogLi,#autoRefreshFileLogLabelLi').hide();
		}else if(logPauseActionField.val()=='1'){
			logPauseActionField.val('0');
			$(link).text('<fmt:message key="page.system.log.pause"/>');
			$('#handRefreshFileLogLi').hide();
			$('#autoRefreshFileLogLi,#autoRefreshFileLogLabelLi').show();
			setTimeout('ajaxConsole(true)',$(':hidden[name=logAutoRefreshTime]').val());
		}
	}
//-->
</script>

<div class="pageContent">
	<form action="<c:url value="/system/log/config"/>"
		method="post" onsubmit="return validateCallback(this, navTabAjaxDone)">
	<input type="hidden" name="logPauseAction" value="0">
	<input type="hidden" name="logAutoRefreshTime" value="3000">
	<input type="hidden" name="logFileLength" value="${logFileLength}">
	<textarea style="width: 99%;padding: 10px 5px;background-color: white;color: black;" layoutH="56" readonly="readonly" name="logFileContent"><fmt:message key="page.system.log.tip.initlog"/>${logFileContent}</textarea>
	<div class="formBar">
		<ul style="float: left;">			
			<li style="padding-top: 5px;"><fmt:message key="page.system.log.frontcolor"/>：</li>
			<li>				
				<select class="combox" style="width: 3em;" onchange="$('textarea[name=logFileContent]').css('color',this.value);">
					<option value="red"><fmt:message key="page.common.color.red"/></option>
					<option value="#F5B50D"><fmt:message key="page.common.color.yello"/></option>
					<option value="blue"><fmt:message key="page.common.color.blue"/></option>
					<option value="green"><fmt:message key="page.common.color.green"/></option>
					<option value="white"><fmt:message key="page.common.color.white"/></option>
					<option value="black" selected="selected"><fmt:message key="page.common.color.black"/></option>
				</select>
			</li>
			<li style="padding-top: 5px;"><fmt:message key="page.system.log.backgroundcolor"/>：</li>
			<li>
				<select class="combox" style="width: 3em;" onchange="$('textarea[name=logFileContent]').css('background-color',this.value);">
					<option value="red"><fmt:message key="page.common.color.red"/></option>
					<option value="#F5B50D"><fmt:message key="page.common.color.yello"/></option>
					<option value="blue"><fmt:message key="page.common.color.blue"/></option>
					<option value="green"><fmt:message key="page.common.color.green"/></option>
					<option value="white" selected="selected"><fmt:message key="page.common.color.white"/></option>
					<option value="black"><fmt:message key="page.common.color.black"/></option>
				</select>
			</li>
			<li id="autoRefreshFileLogLabelLi" style="padding-top: 5px;"><fmt:message key="page.system.log.autorefreshtime"/>：</li>
			<li id="autoRefreshFileLogLi" >
				<select class="combox" style="width: 3em;" onchange="$(':hidden[name=logAutoRefreshTime]').val(this.value)">
					<option value="3000" selected="selected">3</option>
					<option value="6000">6</option>
					<option value="9000">9</option>
					<option value="12000">12</option>
				</select>
			</li>
			<li id="handRefreshFileLogLi" style="padding-top: 5px;display: none;">
				<a href="#" onclick="ajaxConsole(false)"><fmt:message key="page.system.log.handrefresh"/></a>
			</li>
			<li style="padding-top: 5px;">
				<a href="#" onclick="pauseLog(this)"><fmt:message key="page.system.log.pause"/></a>
			</li>
			<li style="padding-top: 5px;">
				<a href="#" onclick="$('textarea[name=logFileContent]').text('<fmt:message key="page.system.log.tip.afterclearscreen"/>\n');"><fmt:message key="page.system.log.clearscreen"/></a>
			</li>
		</ul>
		<ul style="float: right;">
			<li>
				<div class="button">
					<div class="buttonContent">
						<button type="button" class="close"><fmt:message key="page.button.cancel"/></button>
					</div>
				</div>
			</li>
		</ul>
	</div>
	</form>
</div>